﻿using System;
using System.Data.SqlClient;

namespace Project.dalSql
{
    public class SqlBaseCommand
    {
        public SqlBaseCommand(Int64 _RecordCount)
        {
            RecordCount = _RecordCount;
            _ComparisonType = EnumComparisonType.Than;
            Command = new SqlCommand();
        }

        public SqlBaseCommand(Int64 _RecordCount, EnumComparisonType _ComparisonType)
        {
            RecordCount = _RecordCount;
            ComparisonType = _ComparisonType;
            Command = new SqlCommand();
        }

        private Int64 _RecordCount;

        /// <summary>
        /// 应该影响的记录数
        /// </summary>
        public Int64 RecordCount
        {
            get { return _RecordCount; }
            set { _RecordCount = value; }
        }

        private EnumComparisonType _ComparisonType;

        /// <summary>
        /// 应该影响的记录数
        /// </summary>
        public EnumComparisonType ComparisonType
        {
            get { return _ComparisonType; }
            set { _ComparisonType = value; }
        }


        private SqlCommand _Command;

        public SqlCommand Command
        {
            get { return _Command; }
            set { _Command = value; }
        }


        public Boolean Comparison(Int64 ImpactRecordCount)
        {
            Boolean IsSuccess = false;
            switch (ComparisonType)
            {
                case EnumComparisonType.Than:
                    IsSuccess = ImpactRecordCount > RecordCount;
                    break;
                case EnumComparisonType.Less:
                    IsSuccess = ImpactRecordCount < RecordCount;
                    break;
                case EnumComparisonType.Equal:
                    IsSuccess = ImpactRecordCount == RecordCount;
                    break;
            }
            return IsSuccess;
        }
    }


    public enum EnumComparisonType
    {
        Than,        //大于
        Less,//小于
        Equal//等于
    }
}
